package com.idlecode.factory;

import com.idlecode.panel.CodeGenerationPanel;
import com.idlecode.panel.DataSourcesPanel;
import com.idlecode.panel.FieldTypeMappingPanel;
import com.idlecode.panel.ToolPanel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
import com.intellij.ui.content.ContentManager;

import javax.swing.*;

/**
 * @program: fluent
 * @description
 * @author: rongjuwei
 * @create: 2024-02-05 15:16
 **/
public class IdleCodeFactory implements ToolWindowFactory {
    @Override
    public void createToolWindowContent(Project project, ToolWindow toolWindow) {
        // 在这里添加你的 Tool Window 内容
        JPanel panel = new JPanel();
        JLabel label = new JLabel("Hello, Tool Window!");
        panel.add(label);
        ContentManager contentManager = toolWindow.getContentManager();
        ContentFactory contentFactory = contentManager.getFactory();
        //代码生成
        Content codeGenerationContent = contentFactory.createContent(new CodeGenerationPanel(project), "代码生成", true);
        contentManager.addContent(codeGenerationContent);
        //数据源
        Content dataSourcesContent = contentFactory.createContent(new DataSourcesPanel(), "数据源", true);
        contentManager.addContent(dataSourcesContent);
        //字段类型映射
        Content fieldTypeMappingContent = contentFactory.createContent(new FieldTypeMappingPanel(), "字段类型映射", true);
        contentManager.addContent(fieldTypeMappingContent);
        //工具
        Content toolContent = contentFactory.createContent(new ToolPanel(project), "工具", true);
        contentManager.addContent(toolContent);
    }

    @Override
    public boolean shouldBeAvailable(Project project) {
        // 控制 Tool Window 是否应该在当前项目中可用
        return true;
    }
}